local assets = {
    -- Asset("IMAGE", "images/inventoryimages/spell_reject_the_npc.tex"),
	-- Asset("ATLAS", "images/inventoryimages/spell_reject_the_npc.xml"),
	Asset("ANIM", "anim/npc_fx_chat_bubble.zip"),
	Asset("ANIM", "anim/npc_fx_chat_bubble_monsters.zip"),

}


local function fx()
    local inst = CreateEntity()
    inst.entity:AddTransform()
    inst.entity:AddAnimState()
    inst.entity:AddNetwork()

    inst:AddTag("INLIMBO")
    inst:AddTag("FX")
    inst:AddTag("NOBLOCK")
    -- inst:DoTaskInTime(5,inst.Remove)
    -- FX:ListenForEvent("animqueueover",FX.Remove)
    -- FX:ListenForEvent("animoever",FX.Remove)

    inst.AnimState:SetBuild("npc_fx_chat_bubble")
    inst.AnimState:SetBank("npc_fx_chat_bubble")
    inst.AnimState:PlayAnimation("idle")
    inst.AnimState:SetScale(1.3,1.3,1.3)

    ---------------------------------------------------    

    -- inst:AddComponent("talker")
    -- inst.components.talker.offset = Vector3(60, -160, 0)
    -- inst.components.talker.colour = Vector3(255/255 , 255/255 , 255/255)  --- RGB

    if not TheWorld.ismastersim then
        return inst
    end

    -- inst.str = "x 10"
    -- inst:DoPeriodicTask(2,function()
    --     if inst.str ~= nil then
    --         inst.components.talker:Say(inst.str)
    --     end
    -- end)

    inst:ListenForEvent("Show",function(inst,_table)
        -- _table = {
        --     image = "moonrockseed" , -- prefab name
        --     monster = "" ---- prefab name
        --     num = 10,        0~99
        --     pause = nil
        -- }
        if _table and ( _table.image or _table.monster) then
            if _table.num == nil then
                inst.AnimState:PlayAnimation("idle_mid",not _table.pause)
            elseif _table.num ~= nil and type(_table.num) == "number" then
                if _table.num < 10 then
                    inst.AnimState:PlayAnimation("idle_low",not _table.pause)
                else
                    inst.AnimState:PlayAnimation("idle",not _table.pause)
                end
            end
            if _table.image then            
                local image = _table.image
                if image == "npc_item_goldnugget_coin" then
                    inst.AnimState:OverrideSymbol("SWAP_SIGN","npc_fx_trade_bubble","coin1")
                else
                    inst.AnimState:OverrideSymbol("SWAP_SIGN", GetInventoryItemAtlas(image..".tex"), image..".tex")
                end
            end
            if _table.monster then
                inst.AnimState:OverrideSymbol("SWAP_SIGN", "npc_fx_chat_bubble_monsters", _table.monster)
            end
            -- inst.str = _table.str
            -- inst.components.talker:Say(inst.str)


            if _table.num then                
                local num = _table.num
                if num < 0 then
                    num = 0
                end
                if num > 99 then
                    num = 99 
                end

                local high =  math.floor(num/10)
                local low = math.floor(num%10)
                if high == 0 then
                    inst.AnimState:HideSymbol("SWAP_SIGN_HIGH")
                else
                    inst.AnimState:ShowSymbol("SWAP_SIGN_HIGH")                    
                end

                inst.AnimState:OverrideSymbol("SWAP_SIGN_HIGH", "npc_fx_chat_bubble", tostring(high))
                inst.AnimState:OverrideSymbol("SWAP_SIGN_LOW", "npc_fx_chat_bubble", tostring(low))

            end

        end

    end)


    inst:DoTaskInTime(0.1,function()
        if inst.Ready ~= true then
            inst:Remove()
        end
    end)



    return inst
end

return Prefab("npc_fx_chat_bubble",fx,assets)